#include"log.hpp"
#include"initpipe.hpp"
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>

int main()
{
    Log log;
    Init init;
    int fd = open(FIFO_FILE,O_RDONLY);
    log.enable(OneFile);
    if(fd < 0)
    {
        log(Fatal,"error string is:%s,error code is:%d",strerror(errno),errno);
        exit(FILE_OPEN_ERR);
    }
    log(Info,"Open Well!!!!");
    log.enable(ClassFile);

    log(Info,"server info well");
    log(Warning,"server Warning well");
    log(Error,"server Error well");
    log(Fatal,"server Fatal well");

    
    //开始通信：
    while(true)
    {
        char buffer[1024];
        int n = read(fd,buffer,sizeof(buffer));
        if(n > 0)
        {
            std::cout << "client say @" <<buffer << std::endl;
        }
        else if(n == 0)
        {
            std::cout << "通讯结束！！"<<std::endl;
            log(Debug,"client is shutdown,test over!!!");
            break;
        }
    }

    close(fd);
    log(Info,"输入信息到Info日志");
    return 0;
}